package com.yenlien.traceyun.milk.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.milk.dao.FarmersDao;
import com.yenlien.traceyun.milk.dao.MilkManageDao;
import com.yenlien.traceyun.milk.entity.Farmers;
import com.yenlien.traceyun.webase.controller.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import static cn.afterturn.easypoi.util.PoiCssUtils.log;

/**
 * @Date 2022/7/11
 * @Author jiaLong
 * @Descript 奶站大屏接口
 */
@Api(tags = "奶站大屏接口")
@RestController
@RequestMapping("/home")
public class HomeController extends BaseController {

    @Autowired
    private MilkManageDao milkManageDao;

    @Autowired
    private FarmersDao farmersDao;



    @PostMapping(value = "/home")
    public Object findByList(@RequestBody Farmers farmers) {
        JSONObject object = new JSONObject();
        object.put("milkCnt", milkManageDao.cnt());
        object.put("farmerCnt", farmersDao.cnt());


        return success("");
    }



    @GetMapping("/getCookie")
    public Object getCookie(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        String targetCookieName = "access_token";
        // 遍历 Cookie 数组，查找目标名称的 Cookie
        Cookie targetCookie = null;
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.getName().equals(targetCookieName)) {
                    targetCookie = cookie;
                    break;
                }
            }
        }
        // 判断目标 Cookie 是否找到
        if (targetCookie != null) {
            // 找到了目标 Cookie，获取其值
            String targetCookieValue = targetCookie.getValue();
            // 进行后续的处理逻辑
            System.out.println("accessToken================="+targetCookieValue);
            return success(targetCookieValue);
        } else {
            // 没有找到目标 Cookie
            System.out.println("accessToken=================null");
            return fail("accessToken没找到");
        }
    }







}
